/*
 *  $Id: Paralysis.cs 975 2009-12-16 17:13:22Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Affects {
    /// <summary>
    /// Эффект: паралич
    /// Параметры: сила паралича
    /// Цель не может двигаться, пока в начале хода не выпадет dХ и выше.
    /// </summary>
    public class Paralysis: FlagAffect {
        private static readonly Languages.Phrase Try = new Languages.Phrase("affect.paralysis.try");

        public readonly int Value;
        public bool Failed;

        public Paralysis(int value) {
            Value = value;
            Failed = false;
        }

        public override string Id {
            get { return "paralysis"; }
        }
        public override string NameText {
            get { return Name.GetText(Value); }
        }

        public override int BaseWeight {
            get { return (7-Value) * -30; }
        }

        public override AffectIcon Icon {
            get { return AffectIcon.Paralysis; }
        }

        public override bool IsEnded {
            get { return Failed; }
        }

        public override Affect Clone() {
            return new Paralysis(Value);
        }

        public override void SetAffect() {
            base.SetAffect();
            LocalSummary.OnStartOffencePhase += DoParalysis;
        }
        public override void ResetAffect() {
            base.ResetAffect();
            LocalSummary.OnStartOffencePhase -= DoParalysis;
        }

        private void DoParalysis() {
            if (Failed) return;
            int dice = Game.Current.GetDiceNextValue();
            bool success = dice >= Value;
            Game.Current.Log.Add(Try, Owner, dice, Resources.Game.Success(success));
            if (success)
                Failed = true;
        }
    }
}